package com.yan.design.two.structure.s4;

import lombok.ToString;

import java.util.ArrayList;
import java.util.List;

/**
 * 4. 组合模式
 *     文件类  - 树叶子 - 叶子节点不能再有子节点
 * @author shengren.yan
 * @create 2022-07-27
 */
@ToString
public class File extends Component{

    List<Component> list = new ArrayList<>();


    public File(String name,String age){
        super(name,age);
    }

    @Override
    public void print(){

        System.out.println("--------" + getName());
        // 叶子节点不需要 向下遍历
//        list.forEach(Component::print);
    }

    @Override
    public void add(Component c) {
        // 抛异常
        throw  new UnsupportedOperationException();
//        list.add(c);
    }

    @Override
    public void remove(Component c) {
        throw  new UnsupportedOperationException();
//        list.remove(c);
    }

    @Override
    Component getChild(int index) {
        throw  new UnsupportedOperationException();
//        return list.get(index);
    }

    @Override
    public void test() {
        System.out.println("可以ok " + this);
    }

    public String getName() {
        return super.getName();
    }

}
